import LabDesign from "./LabDesign";

export default {
    mixins: [LabDesign],
    inject: {
        /**
         * 框架方法
         * refreshTag 刷新当前页
         * closeTag   关闭当前页
         */
        $LabWeb: {
            from: '$LabWeb',
            default: function () {
                return undefined
            }
        },
        /**
         * 流程方法注入
         */
        $labProcess: {
            from: '$labProcess',
            default: function () {
                return undefined
            }
        },
        /**
         * 应用信息注入
         */
        appInfo: {
            from: 'appInfo',
            default: function () {
                return { appId: '0' }
            }
        },
        /**
         * 父级组件对象
         */
        parentElement: {
            from: 'parentElement',
            default: function () {
                return null
            }
        },
        /**
         * 当前组件所属视图Dom对象
         */
        parentView: {
            from: 'parentView',
            default: function () {
                return null
            }
        },
        /**
         * 当前组件所属视图对象
         */
        viewInfo: {
            from: 'viewInfo',
            default: function () {
                return null
            }
        }
    },
    props: {
        /**
         * 当前组件
         */
        element: {
            type: Object,
            default: function () {
                return { elements: [], props: {} }
            }
        },
        /**
         *  当前组件所属的集合
         */
        elements: {
            type: Array,
            default: function () {
                return []
            }
        },
        /**
         * 当前组件在所属集合的索引下标
         */
        index: {
            type: Number,
            default: -1
        },
        /**
         * 当前业务对象
         */
        modelData: {
            type: Object,
            default: function () {
                return { }
            }
        }
    },
    data () {
        return {
            /**
             * 当前样式
             */
            selfStyle: {},
            /**
             * 当前数据模式，优先从父级组件获取
             * add、edit、view、hide
             */
            selfType: 'edit'

        }
    },
    computed: {
        api() {
            return process.env.VUE_APP_BASE_API
        },
        userInfo(){
            return this.$store.state.userInfos.userInfo;
        }
    },
    created() {
        this.selfStyle = this.$Util.copy(this.element.style)
        if (this.element.selfType) {
            this.selfType = this.element.selfType
        }/* else if (this.parentElement) {
            this.selfType = this.parentElement.selfType
        }*/
        if (this.element.render === 'divider') {
            this.element.labelWidth = '0'
        }
    },
    methods: {
        condition(item) {
            if (!item.renderCondition || this.labDesign.switch) {
                return item.visible
            }
            const execDefine = ['modelData','$labProcess']
            const execArgs = [this.modelData, this.$labProcess]
            execDefine.push('return ' + item.renderCondition)
            const customFun = Function.apply(null, execDefine)
            return customFun.apply(null, execArgs)
        }
    }
}
